import axios from 'axios';
import  ResUtil  from '@/utils/resUtil';
import type Assistant from "@/types/response/assistant";
import axiosManager from "../axiosManager";
import type { DataType } from "@/types/response";
const instance = axiosManager.assistantAxios;

//新增助理
async function createAssistant(assistant: Assistant) {
    let res = await instance.post("/assistant", assistant);
    return ResUtil.getData<Assistant>(res);
}

//修改助理信息
async function updateAssistant(assistant: Assistant) {
    let res = await instance.put("/assistant", assistant);
    return ResUtil.isSuccess(res);
}

//根据手机号获得助理信息
async function getAssistantByPhone(phoneNum: string) {
    let res = await instance.get("/assistant/phone", {
        params: { phoneNum }
    });
    if (ResUtil.isSuccess(res)) {
        return ResUtil.getData<Assistant>(res);
    }
    return null;
}

//获得 所有 助理信息
async function getAllAssistant() {
    let res = await instance.get("/assistants");
    if (ResUtil.isSuccess(res)) {
        return ResUtil.getData<Assistant[]>(res);
    }
    return null;
}

//获得助理信息
async function getAssistant(assistantId: number) {
    let res = await instance.get("/assistant", {
        params: { assistantId }
    });
    if (ResUtil.isSuccess(res)) {
        return ResUtil.getData<Assistant>(res);
    }
    return null;
}

export { getAssistant, createAssistant, updateAssistant, getAllAssistant, getAssistantByPhone };
